package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Lesson;
import cn.wolfcode.crm.query.LessonQueryObject;
import cn.wolfcode.crm.service.ILessonService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

;

@Controller
@RequestMapping("lesson")
public class LessonController {
    @Autowired
    private ILessonService lessonService;

    @RequiresPermissions(value = {"lesson:view", "员工查看"}, logical = Logical.OR)
    @RequestMapping("view")
    public String view() {
        return "lesson/lesson";
    }

    @RequiresPermissions(value = {"lesson:query", "员工列表"}, logical = Logical.OR)
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(LessonQueryObject qo) {
        return lessonService.quey4List(qo);
    }

    @RequiresPermissions(value = {"lesson:saveOrUpdate", "员工新增/编辑"}, logical = Logical.OR)
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Lesson entity) {
        try {
            lessonService.saveOrUpdate(entity);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }



    //导入课程
//    @RequestMapping("importXls")
//    @ResponseBody
//    public JsonResult importXls(MultipartFile file, HttpServletResponse response) throws Exception {
//        try {
//            lessonService.importXls(file, response);
//            return new JsonResult();
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
//        }
//    }


//    /**
//     * 获取文件上传模板
//     *
//     * @param response
//     * @throws Exception
//     */
//    @RequestMapping("getImportXlsMode")
//    public void importXlsMode(HttpServletResponse response) throws Exception {
//        //设置文件下载响应头
//
//        response.setHeader("Content-Disposition", "attachment;filename=lesson.xls");
//
//        Workbook book = lessonService.getImportXlsMode();
//
//        //写入数据输出到浏览器
//        book.write(response.getOutputStream());
//    }
}
